#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    long prev = LONG_MIN;
    bool isValidBST(TreeNode* root)
    {
        if (root == nullptr) return true;

        bool left = isValidBST(root->left);
        if (left == false) return false;

        bool cur = false;
        if (root->val > prev)
            cur = true;
        if (cur == false) return false;
        prev = root->val;

        bool right = isValidBST(root->right);
        return left && right && cur;
    }
};